<?php
include('config.php');
session_start();
$current_user=$_SESSION['myusername'];

$results = mysql_query("SELECT * FROM users WHERE username = '$current_user'");
$user = mysql_fetch_array($results);

$firstName = $user['firstName'];
$lastName = $user['lastName'];
$email = $user['email'];
?>
<form id="userProfileForm" action="" method="get">
	First Name: <input type="text" class="input" value="<?php echo $firstName; ?>" /><br/>
	Last Name: <input type="text" class="input" value="<?php echo $lastName; ?>" /><br/>
	E-mail: <input type="text" class="input" value="<?php echo $email; ?>" /><br/>
	<input type="button" id="userProfileSubmit" value="Update Profile" />
</form>
<br/>
<form id="userPasswordForm" action="" method="get">
	New Password: <input type="password" id="newPassword1" class="input" /><br/>
	Re-Type Password: <input type="password" id="newPassword2" class="input" /><br/>
	<input type="button" id="userPasswordSubmit" value="Change Password" />
</form>

<script type="text/javascript">
	$('userProfileSubmit').addEvent('click', function(e){
                
		var url = 'pages/query.php?';
                url=url+'firstName='+$('userFirstName').value;
                url=url+'&lastName='+$('userLastName').value;
                url=url+'&email='+$('userEmail').value;
                url=url+'&cmd=updateProfile';
              	url=url+'&nocache='+Math.random();
                MochaUI.updateContent({
               		'element': $('panel1'),
                        'loadMethod': 'xhr',
                        'url': url,
                        'title': 'Results',
                        'padding': { top: 8, right: 8, bottom: 8, left: 8 }
             	});
                MochaUI.notification('Profile Updated Successfully');
   	});
       
	$('userPasswordSubmit').addEvent('click', function(e){
		if ($('newPassword1').value == $('newPassword2').value) {
			var url='pages/query.php?';
			url=url+'cmd=changePassword';
			url=url+'&password='+$('newPassword1').value;
			url=url+'&nocache='+Math.random();
			MochaUI.updateContent({
				'element': $('panel1'),
				'loadMethod': 'xhr',
				'url': url,
				'title': 'Results',
				'padding': { top: 8, right: 8, bottom: 8, left: 8 }
			});
		}
		else {
			MochaUI.notification('Passwords do not match');
		}
	});

</script>
